indexApp
    .controller(
        'Modelling',
        function($scope, $http, $timeout,$interval) {

            //$scope.url = "http://119.167.221.16:23000/";
            $scope.url = "http://127.0.0.1:3000/";
            function getURLParameters(){
                var url=decodeURI(location.href);
                var paramArr = url.substring(url.indexOf("?")+1,url.length).split("&");
                var params = {};
                for(var i = 0 ; i < paramArr.length; i ++){
                    var a=paramArr[i].split('=');
                    params[a[0]] = a[1];
                }
                console.log("params",params);
                return params;
            }
            $scope.urlParams = getURLParameters();
            $scope.predictstart=function(){
                var url = decodeURI(location.href);
                window.location=encodeURI(url.replace("Modelling.html?", "predictData.html?"));
            };


            /**
             * 建模相关控制器
             */
            $scope.currentTask={
                uid:null,
                n_estimators:50,
                criterion:"gini",
                max_depth:20,
                random_state:0,
                bootstrap:"True",
                oob_score:"False",
                tableName:null,
                lableTableName:null
            };
            $scope.KmeansTask={
                uid:null,
                n_clusters:2,
                init:'k-means++',
                n_init:10,
                max_inter:100,
                random_state:0,
                flage:0,
                K:3,
                tableName:null
            };
            $scope.TrainScore=null;
            $scope.TestScore=null;
            $scope.ModelList=['随机森林','Kmeans聚类','KNeighborsClassifier','AdaBoostClassifier'];
            $scope.RFshow=false;
            $scope.KMshow=false;
            $scope.KNNshow=false;
            $scope.Adashow=false;
            $scope.modelIndex=null;
            $scope.pcaShow=false;
            $scope.pcaK=null;
            $scope.score=null;
            $scope.kmeansShow=false;
            var allserval=[];

            $scope.switchModel=function(){
                $scope.RFshow=false;
                $scope.KMshow=false;
                $scope.KNNshow=false;
                $scope.Adashow=false;
                var modelindex=parseInt($scope.modelIndex);
                if (modelindex==0){
                    $scope.RFshow=true;
                }else if(modelindex==1){
                    $scope.KMshow=true;
                }else if(modelindex==2){
                    $scope.KNNshow=true;
                }else if(modelindex==3){
                    $scope.Adashow=true;
                }
            };
            $scope.pcaSet=function(){
                $scope.pcaShow=true;
                $scope.KmeansTask.flage=1;
            };
            $scope.startModelling=function () {
                var url=decodeURI(location.href);
                /*
                $scope.currentTask.tableName=url.substring(url.indexOf("?")+11,url.indexOf("&"));
                $scope.currentTask.uid=url.substring(url.indexOf("&")+8,url.length);
                */
                $scope.currentTask.tableName=$scope.urlParams.tablename;
                $scope.currentTask.uid=$scope.urlParams.taskId;
                $scope.currentTask.n_estimators=parseInt($scope.currentTask.n_estimators);
                $scope.currentTask.max_depth=parseInt($scope.currentTask.max_depth);
                $scope.currentTask.random_state=parseInt($scope.currentTask.random_state);
                $scope.KmeansTask.K=parseInt($scope.pcaK);
                console.log($scope.currentTask);
                var X=[];
                $http({
                    method: 'post',
                    url: $scope.url + 'randomforest',
                    data:$scope.currentTask
                }).then(function (resp, status) {
                    console.log(resp.data);
                    //$scope.currentMySQLTablePre.name=resp.data;
                    $scope.TrainScore=resp.data.TrainScore;
                    $scope.TestScore=resp.data.TestScore;
                    var predata=resp.data.prediceList;
                    var labledata=resp.data.lableList;
                    var testlen=labledata.length;
                    for(var i in testlen){
                        X.push(i);
                    }
                    $scope.linerChart(predata,labledata,X,'testsetChart');
                    var pretraindata=resp.data.prediceTarinList;
                    var labletraindata=resp.data.lableTrainList;
                    var trainlen=labletraindata.length;
                    for(var i in trainlen){
                        X.push(i);
                    }
                    $scope.linerChart(pretraindata,labletraindata,X,'trainsetChart');
                    swal({
                        title: '完成！',
                        timer: 2000
                    });
                    $scope.status = status;
                }, function (resp, status) {
                    $scope.resp = resp;
                    $scope.status = status;
                });
            };


            $scope.linerChart = function (predictData,realDatas,X,chart){

                // 指定图表的配置项和数据
                echarts.init(document.getElementById(chart),'dark').dispose();
                var option = {
                    title : {
                        text: '标签散点图',
                        subtext: '预测标签&实际标签对比'
                    },
                    tooltip : {
                        trigger: 'axis'
                    },
                    legend: {
                        data:['最大值','最小值']
                    },
                    toolbox: {
                        show : true,
                        feature : {
                            mark : {show: true},
                            dataView : {show: true, readOnly: false},
                            magicType : {show: true, type: ['bar', 'stack']},
                            restore : {show: true},
                            saveAsImage : {show: true}
                        }
                    },
                    calculable : true,
                    xAxis : [
                        {
                            type : 'category',
                            boundaryGap : false,
                            data : X
                        }
                    ],
                    yAxis : [
                        {
                            type : 'value',
                        }
                    ],
                    series : [
                        {
                            name:'predictData',
                            type:'bar',
                            data:predictData,
                            markPoint : {
                                data : [
                                    {type : 'max', name: '最大值'},
                                    {type : 'min', name: '最小值'}
                                ]
                            },
                            markLine : {
                                data : [
                                    {type : 'average', name: '平均值'}
                                ]
                            }
                        },
                        {
                            name:'realData',
                            type:'bar',
                            data:realDatas,
                            markPoint : {
                                data : [
                                    {type : 'max', name: '最大值'},
                                    {type : 'min', name: '最小值'}
                                ]
                            },
                            markLine : {
                                data : [
                                    {type : 'average', name: '平均值'}
                                ]
                            }
                        }
                    ]
                };
                var echartsWarp = document.getElementById(chart);
                var myChart = echarts.init(echartsWarp,'dark');// 基于准备好的dom，初始化echarts实例
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
                window.addEventListener("resize", function () {
                    myChart.resize();
                });
            };
            /**
             * Kmeans聚类
             * @type {{}}
             */

            $scope.classMap={};
            $scope.nowclassMap={};
            var featuresRawData =null;
            $scope.itemList=[];
            $scope.featurePanelState = "收起";
            $scope.outputPanelState = "展开";
            $scope.visualizationState = "展开";
            $scope.predictPanelState = "展开";
            $scope.dataFeaturesDivVisible=true;
            $scope.dataOuputDivVisible=false;
            $scope.clusterPredictedPanelVisible=false;
            $scope.taskOuputDivVisible=false;
            $scope.tableItemPre=[];
            $scope.mysqlTableSampleDataPre=[];
            $scope.itemTypePre={};
            $scope.countItemPre=[];
            $scope.pointToPredict={};
            $scope.modelRecord={
                modelName:null,
                tableName:$scope.urlParams.tablename,
                oldTableName:$scope.urlParams.oldtablename,
                className:null,
                uid:$scope.urlParams.taskId
            };
            $scope.getDataVisualization=function(){
                if ($scope.visualizationState=='展开'){
                    $scope.kmeansShow=true;
                    $scope.visualizationState='收起';
                }else {
                    $scope.kmeansShow=false;
                    $scope.visualizationState='展开';
                }
            };
            $scope.getFeaturesData=function(){
                if ($scope.featurePanelState=='展开'){
                    $scope.dataFeaturesDivVisible=true;
                    $scope.featurePanelState='收起';
                }else {
                    $scope.dataFeaturesDivVisible=false;
                    $scope.featurePanelState='展开';
                }
            };
            $scope.getClusteringOutputRawData=function(){
                if ($scope.outputPanelState=='展开'){
                    $scope.getPreDataSample();
                    $scope.dataOuputDivVisible=true;
                    $scope.outputPanelState='收起';
                }else {
                    $scope.dataOuputDivVisible=false;
                    $scope.outputPanelState='展开';
                }
            };
            $scope.showClusterPredict=function(){
                if ($scope.predictPanelState=='展开'){
                    $scope.clusterPredictedPanelVisible=true;
                    $scope.predictPanelState='收起';
                }else {
                    $scope.clusterPredictedPanelVisible=false;
                    $scope.predictPanelState='展开';
                }
            };
            $scope.KmeansModelling=function () {
                var centerServal=[];
                allserval=[];
                /*
                var url=decodeURI(location.href);
                $scope.KmeansTask.tableName=url.substring(url.indexOf("?")+11,url.indexOf("&"));
                $scope.KmeansTask.uid=url.substring(url.indexOf("&")+8,url.length);
                */

                $scope.KmeansTask.tableName=$scope.urlParams.tablename;
                $scope.KmeansTask.uid=$scope.urlParams.taskId;
                console.log("KmeansTask.tableName",$scope.KmeansTask.tableName);
                $scope.KmeansTask.n_clusters=parseInt($scope.KmeansTask.n_clusters);
                $scope.KmeansTask.flage=parseInt($scope.KmeansTask.flage);
                $scope.KmeansTask.random_state=parseInt($scope.KmeansTask.random_state);
                $scope.KmeansTask.max_inter=parseInt($scope.KmeansTask.max_inter);
                $scope.KmeansTask.n_init=parseInt($scope.KmeansTask.n_init);
                $scope.KmeansTask.K=parseInt($scope.KmeansTask.K);
                for (var i=0; i<$scope.KmeansTask.n_clusters;i++){
                    $scope.classMap[i]="第"+(i+1)+"簇";
                    $scope.nowclassMap[i]="第"+(i+1)+"簇"
                }
                console.log("classMap",$scope.classMap);
                console.log($scope.KmeansTask);
                var X=[];
                $http({
                    method: 'post',
                    url: $scope.url + 'kmeans',
                    data:$scope.KmeansTask
                }).then(function (resp, status) {
                    console.log(resp.data);
                    var classfiyData=resp.data.classfiyData;
                    var centerData=resp.data.centers;
                    $scope.score=resp.data.scores;
                    $scope.featureMeta=resp.data.ItemList;
                    $scope.featuresRawData=resp.data.classPar;
                    $scope.modelRecord.modelName=resp.data.modelName;
                    featuresRawData = resp.data.classPar;
                    console.log("ItemList",$scope.featureMeta);
                    chartShow();
                    console.log(classfiyData);
                    console.log(centerData);
                    for(var i in centerData){
                        var centerList=[];
                        var serval={
                            type: 'scatter3D',
                            dimensions: ['a', 'b', 'c'//显示框信息
                            ],
//                encode: {
////                    x: [3, 1, 5],      // 表示维度 3、1、5 映射到 x 轴。
////                    y: 2,              // 表示维度 2 映射到 y 轴。
//                    tooltip:['a','c','b'], // 表示维度 3、2、4 会在 tooltip 中显示。
//                    label: 'a'           // 表示 label 使用维度 3。
//                },
                            data: [],
                            symbolSize: 10,//点的大小
                            // symbol: 'triangle',
                            itemStyle: {
                                borderWidth: 50,
                                borderColor: 'rgba(255,255,255,0.8)'//边框样式
                            },
                            emphasis: {
                                itemStyle: {
                                    color: '#ccc'//高亮
                                }
                            },
                            itemStyle: {
                                color: '#ffee00'
                            }
                        };
                        serval.data.push(centerData[i]);
                        console.log("data",serval.data);
                        centerServal.push(serval);
                    }
                    for(var j=0;j<$scope.KmeansTask.n_clusters;j++){
                        var serval={
                            type: 'scatter3D',
                            dimensions: ['a', 'b', 'c'//显示框信息
                            ],
//                encode: {
////                    x: [3, 1, 5],      // 表示维度 3、1、5 映射到 x 轴。
////                    y: 2,              // 表示维度 2 映射到 y 轴。
//                    tooltip:['a','c','b'], // 表示维度 3、2、4 会在 tooltip 中显示。
//                    label: 'a'           // 表示 label 使用维度 3。
//                },
                            data: [],
                            symbolSize: 10,//点的大小
                            // symbol: 'triangle',
                            itemStyle: {
                                borderWidth: 50,
                                borderColor: 'rgba(255,255,255,0.8)'//边框样式
                            },
                            emphasis: {
                                itemStyle: {
                                    color: '#ccc'//高亮
                                }
                            },
                            itemStyle: {
                                color: null
                            }
                        };
                        templist=[];
                        var templist=[];
                        templist=classfiyData[i];
                        serval.data=classfiyData[j];
                        console.log("dataserval",serval.data);
                        serval.itemStyle.color=getRandomColor();
                        allserval.push(serval);
                    }
                    allserval=allserval.concat(centerServal);
                    console.log("all",allserval);
                    $scope.get3dchart();
                    swal({
                        title: '完成！',
                        timer: 2000
                    });
                    $scope.taskOuputDivVisible=true;
                    //$scope.currentMySQLTablePre.name=resp.data;
                    $scope.status = status;
                }, function (resp, status) {
                    $scope.resp = resp;
                    $scope.status = status;
                });
            };


            $scope.get3dchart=function () {
                var myChart = echarts.init(document.getElementById('3DChart'),'dark');
                console.log(myChart);
                myChart.setOption({
                    tooltip: {},
                    xAxis3D: {
                        name: "x",
                        type: 'value',
//                min: 'dataMin',//获取数据中的最值
//                max: 'dataMax'
                    },
                    yAxis3D: {
                        name: "y",
                        type: 'value',
//                min: 'dataMin',
//                max: 'dataMax'
                    },
                    zAxis3D: {
                        name: "z",
                        type: 'value',
//                min: 'dataMin',
//                max: 'dataMax'
                    },
                    grid3D: {
                        axisLine: {
                            lineStyle: {
                                color: '#000'//轴线颜色
                            }
                        },
                        axisPointer: {
                            lineStyle: {
                                color: '#80ff59'//坐标轴指示线
                            },
                            show: true//不坐标轴指示线
                        },
                        viewControl: {
//                     autoRotate: true,//旋转展示
//                     projection: 'orthographic'
                            beta: 10
                        },
                        boxWidth: 200,
                        boxHeight: 100,
                        boxDepth: 100,
                        top: -100
                    },

                    series: allserval,
                    backgroundColor: "#fff"
                },true);

            }
            var getRandomColor = function () {
                var r = Math.round(Math.random() * 255), g = Math.round(Math.random() * 255), b = Math.round(Math.random() * 255);
                var color = r << 16 | g << 8 | b;
                return "#" + color.toString(16)
            };
            $scope.setLabelInput=function (key,newVaule) {
                $scope.nowclassMap[key]=newVaule;
                console.log("classMap",$scope.nowclassMap);
            };
            $scope.saveLabel=false;
            $scope.saveClusteringLabels=function () {
                chartShow();
                $scope.modelRecord.className=$scope.nowclassMap;
                $http({
                    method: 'post',
                    url: $scope.url + 'labeltotable',
                    data:$scope.modelRecord
                }).then(function (resp, status) {
                    $scope.currentMySQLTablePre.name=resp.data.predictTableName;
                    console.log("predictTableName",$scope.currentMySQLTablePre.name);
                    $scope.saveLabel=true;
                    $scope.status = status;
                }, function (resp, status) {
                    $scope.resp = resp;
                    $scope.status = status;
                });
            };

            var chartShow = function() {
                var colNum = $scope.featureMeta.length;
                $scope.thHtml = "";
                for (var i = 0 ; i < colNum; i++){
                    $scope.thHtml += "<th>最小值</th><th>最大值</th><th>均值</th>";
                }
                var featuresHtml = "";
                for (var item in featuresRawData){
                    featuresHtml += "<tr><td>" + $scope.nowclassMap[item] + "</td>";
                    for (var col in featuresRawData[item]){
                        featuresHtml += "<td>" + featuresRawData[item][col]["min"] + "</td>" +
                            "<td>" + featuresRawData[item][col]["max"] + "</td>" +
                            "<td>" + featuresRawData[item][col]["mean"] + "</td>";
                    }
                    featuresHtml += "<tr>";
                }
                $scope.featuresHtml = featuresHtml;
            };
            $scope.currentMySQLTablePre={
                name:null,
                database:"predictDataSet"
            };
            $scope.getPreDataSample=function () {
                $scope.tableItemPre=[];
                $scope.mysqlTableSampleDataPre=[];
                $scope.itemTypePre={};
                $scope.countItemPre=[];
                $http({
                    method: 'post',
                    url: $scope.url + 'gettableItem',
                    data:$scope.currentMySQLTablePre
                }).then(function (resp, status) {
                    $scope.tableItemPre=resp.data.res;
                    console.log($scope.tableItemPre);
                    for (var i = 0; i<$scope.tableItemPre.length; i++) {
                        $scope.countItemPre.push(i.toString());
                    }
                    $scope.status = status;
                }, function (resp, status) {
                    $scope.resp = resp;
                    $scope.status = status;
                });
                $http({
                    method: 'post',
                    url: $scope.url + 'getsortsampledata',
                    data:$scope.currentMySQLTablePre
                }).then(function (resp, status) {
                    $scope.mysqlTableSampleDataPre=resp.data.res;
                    console.log($scope.mysqlTableSampleDataPre);
                    $scope.status = status;
                }, function (resp, status) {
                    $scope.resp = resp;
                    $scope.status = status;
                });
            };
            $scope.clusterPredict = function (pointToPredict, task) {
                console
                    .log("[Predict Cluster] You are predict cluster for the task whose id is "
                        + task.taskId);
                $scope.pointToPredict = pointToPredict;
                $scope.clusterPredictedDivVisible = false;
                var predictLabel={
                    modelName:$scope.modelRecord.modelName,
                    data:$scope.pointToPredict,
                    className:$scope.modelRecord.className
                }
                var pointStr = "";
                for (var item in pointToPredict){
                    pointStr += pointToPredict[item] + ",";
                }
                pointStr.substring(0, pointStr.length - 1);
                $scope.initRadarChart();
                $http(
                    {
                        method: 'POST',
                        url: $scope.url + 'labelpredict',
                        data: predictLabel
                    }).then(function (resp, status) {
                    console.log(resp.data);
                    $scope.clusterPredictedDivVisible = true;
                    $scope.predictedCluster = resp.data.predictTableName;
                    console.log($scope.predictedCluster);
                    $scope.initRadarChart();
                }, function (resp, status) {
                    $scope.resp = resp;
                    $scope.status = status;
                });
            };

            $scope.initRadarChart = function (){

                var index = 0; //$scope.predictedCluster["pointNum"];
                console.log( $scope.featureMeta);
                console.log($scope.pointToPredict);
                var max = new Array();
                var avg = new Array();

                var data = new Array();
                for (var item in $scope.pointToPredict){
                    data.push($scope.pointToPredict[item]);
                }
                for (var item in $scope.featuresRawData[index]){
                    max.push({"max": $scope.featuresRawData[index][item]["max"],
                        "name": $scope.featureMeta[item]});
                    avg.push($scope.featuresRawData[index][item]["mean"]);
                }
                console.log(avg);

                var option = {
                    backgroundColor: '#fafafa',
                    tooltip: {},

                    legend: {                        // 图例组件
                        show: true,
                        itemWidth: 10,                  // 图例标记的图形宽度。[ default: 25 ]
                        itemHeight: 10,                 // 图例标记的图形高度。[ default: 14 ]
                        itemGap: 30,                	// 图例每项之间的间隔。[ default: 10 ]横向布局时为水平间隔，纵向布局时为纵向间隔。
                        orient: 'horizontal',             // 图例列表的布局朝向,'horizontal'为横向,''为纵向.

                    },

                    radar: [{                       // 雷达图坐标系组件，只适用于雷达图。
                        center: ['50%', '50%'],             // 圆中心坐标，数组的第一项是横坐标，第二项是纵坐标。[ default: ['50%', '50%'] ]
                        radius: 160,                        // 圆的半径，数组的第一项是内半径，第二项是外半径。
                        startAngle: 90,                     // 坐标系起始角度，也就是第一个指示器轴的角度。[ default: 90 ]
                        name: {                             // (圆外的标签)雷达图每个指示器名称的配置项。
                            formatter: '{value}',
                            textStyle: {
                                fontSize: 15,
                                color: '#292929'
                            }
                        },
                        nameGap: 20,                        // 指示器名称和指示器轴的距离。[ default: 15 ]
                        splitNumber: 5,                     // (这里是圆的环数)指示器轴的分割段数。[ default: 5 ]
                        shape: 'polygon',                    // 雷达图绘制类型，支持 'polygon'(多边形) 和 'circle'(圆)。[ default: 'polygon' ]
                        axisLine: {                         // (圆内的几条直线)坐标轴轴线相关设置
                            lineStyle: {
                                color: '#fff',                   // 坐标轴线线的颜色。
                                width: 1,                      	 // 坐标轴线线宽。
                                type: 'solid',                   // 坐标轴线线的类型。
                            }
                        },
                        splitLine: {                        // (这里是指所有圆环)坐标轴在 grid 区域中的分隔线。
                            lineStyle: {                    // 分隔线颜色
                                width: 0.5, 							 // 分隔线线宽
                            }
                        },
                        splitArea: {                        // 坐标轴在 grid 区域中的分隔区域，默认不显示。
                            show: true,
                            areaStyle: {                            // 分隔区域的样式设置。
                                color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)'],       // 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
                            }
                        },
                        indicator: max
                    }],
                    series: [{         // 系列名称,用于tooltip的显示，legend 的图例筛选，在 setOption 更新数据和配置项时用于指定对应的系列。
                        type: 'radar',              // 系列类型: 雷达图
                        itemStyle: {                // 折线拐点标志的样式。
                            normal: {                   // 普通状态时的样式
                                lineStyle: {
                                    width: 1
                                },
                                opacity: 0.3
                            },
                            emphasis: {                 // 高亮时的样式
                                lineStyle: {
                                    width: 5
                                },
                                opacity: 1
                            }
                        },
                        data: [{                    // 雷达图的数据是多变量（维度）的
                            name: '类别均值',                 // 数据项名称
                            value: avg,        // 其中的value项数组是具体的数据，每个值跟 radar.indicator 一一对应。
                            symbol: 'circle',                   // 单个数据标记的图形。
                            symbolSize: 5,                      // 单个数据标记的大小，可以设置成诸如 10 这样单一的数字，也可以用数组分开表示宽和高，例如 [20, 10] 表示标记宽为20，高为10。
                            label: {                    // 单个拐点文本的样式设置
                                normal: {
                                    show: true,             // 单个拐点文本的样式设置。[ default: false ]
                                    position: 'top',        // 标签的位置。[ default: top ]
                                    formatter:function(params) {
                                        return params.value;
                                    }
                                }
                            },
                            lineStyle: {                // 单项线条样式。
                                normal: {
                                    opacity: 0.5            // 图形透明度
                                }
                            },
                            areaStyle: {                // 单项区域填充样式
                                normal: {
                                    color: "#cd6a67"       // 填充的颜色。[ default: "#000" ]
                                }
                            }
                        }, {
                            name: '用户数据',
                            value: data,
                            symbol: 'circle',
                            symbolSize: 5,
                            label: {
                                normal: {
                                    show: true,
                                    position: 'top',
                                    formatter:function(params) {
                                        return params.value;
                                    }
                                }
                            },
                            lineStyle: {
                                normal: {
                                    opacity: 0.5
                                }
                            },
                            areaStyle: {
                                normal: {
                                    color: '#2f4554'
                                }
                            }
                        }]
                    }, ]
                };


                var echartsWarp = document.getElementById("radarChart");
                var resizeWorldMapContainer = function () {//用于使chart自适应高度和宽度,通过窗体高宽计算容器高宽
                    echartsWarp.style.width = window.innerWidth*0.90+'px';
                    echartsWarp.style.height = window.innerHeight*0.9+'px';
                };

                resizeWorldMapContainer ();//设置容器高宽

                var myChart = echarts.init(echartsWarp);// 基于准备好的dom，初始化echarts实例

                myChart.setOption(option);


            };

        });
indexApp
    .directive(
        'featureChart',
        function () {
            return {
                scope: {
                    id: "@",
                    data: "=",
                    meta: "=",
                    label: "="
                },
                restrict: 'E',
                template: '<div style="height: 600px;"></div>',
                replace: true,
                link: function ($scope, element, attrs, controller) {
                    $scope
                        .$watch(
                            'data',
                            function (newValue, oldValue, scope) {

                                var index = $scope.id.substring(4);

                                var featuresRawData = $scope.data;
                                var label = $scope.label;
                                var categories = new Array();
                                var min = new Array();
                                var max = new Array();
                                var avg = new Array();
                                console.log(label);
                                for (var item in label){
                                    categories.push(label[item]);
                                    console.log(label[item]);
                                }

                                for (var item in featuresRawData){
                                    min.push(featuresRawData[item][index]["min"]);
                                    max.push(featuresRawData[item][index]["max"]);
                                    avg.push(featuresRawData[item][index]["mean"]);
                                }

                                console.log("avg",avg);
                                var echartsWarp = document.getElementById($scope.id);
                                var resizeWorldMapContainer = function () {//用于使chart自适应高度和宽度,通过窗体高宽计算容器高宽
                                    echartsWarp.style.width = window.innerWidth*0.3+'px';
                                    echartsWarp.style.height = window.innerHeight*0.5+'px';
                                };

                                resizeWorldMapContainer ();//设置容器高宽


                                var myChart = echarts.init(echartsWarp);// 基于准备好的dom，初始化echarts实例

                                myChart.setOption({
                                    title: {
                                        text: $scope.meta[index],
                                        textStyle:{
                                            fontWeight: 'lighter'
                                        }
                                    },
                                    tooltip : {
                                        trigger: 'axis',
                                        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                        },
                                        formatter: function (params) {
                                            var tar = params[1];
                                            return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value + "<br>" +
                                                params[0].seriesName + ' : ' +  params[0].value;
                                        }
                                    },
                                    grid: {
                                        left: '3%',
                                        right: '4%',
                                        bottom: '3%',
                                        containLabel: true
                                    },
                                    xAxis: {
                                        type : 'category',
                                        splitLine: {show:false},
                                        data : categories
                                    },
                                    yAxis: {
                                        type : 'value'
                                    },
                                    series: [
                                        {
                                            name: '最小值',
                                            type: 'bar',
                                            barMaxWidth: 20,
                                            stack:  '总量',
                                            itemStyle: {
                                                normal: {
                                                    barBorderColor: '#0000',
                                                    color: '#0000'
                                                },
                                                emphasis: {
                                                    barBorderColor: '#0000',
                                                    color: '#0000'
                                                }
                                            },
                                            data: min
                                        },

                                        {
                                            name: '最大值',
                                            type: 'bar',
                                            stack: '总量',
                                            itemStyle: {
                                                normal: {
                                                    barBorderColor: '#cd6a67',
                                                    color: '#cd6a67'
                                                },
                                                emphasis: {
                                                    barBorderColor: '#cd6a67',
                                                    color: '#cd6a67'
                                                }
                                            },
                                            data: max
                                        },
                                        {
                                            name: '均值',
                                            type: 'line',
                                            label: {
                                                normal: {
                                                    show: true,
                                                    position: 'top',
                                                    color: "#292929"
                                                }
                                            },
                                            itemStyle: {
                                                color: '#39546b'
                                            },
                                            data: avg
                                        }
                                    ]
                                });

                                myChart.resize();

                            });
                }
            };
        });





indexApp.filter('trustHtml', function ($sce) {
    return function (input) {
        return $sce.trustAsHtml(input);
    }
});

// inspur部署时差问题
indexApp.filter('myDate', function() {
    return function(myDate) {

        return myDate;
    }
});